<template>
  <div class="content-box">
    <nav-title title="银行账号信息" />
    
    <div class="line">
      <span class="important"></span>
      <div class="label">开户银行名称</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="bankVal" v-model="bank.bankCd"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">分/支行</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="bank.rsBranchNm" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">银行账号</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="bank.accountEcId" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">账户名称</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="bank.accountName" readonly="readonly">
      </div>
    </div>
    <div class="submit-btn" @click="save" v-if="showOr">
      保存
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { getDicItem,savePbnk,getBank } from '../../../api/api'
import { json2Form } from '../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    this.getBanklb()
  },
  data() {
    return {
      bank:{
        emplid: '',
        cModStauts:'U',
        cTransactionNbr:''
      },
      showOr:true,
      bankVal:[],
    }
  },
  created() {
    this.getBanks()
  },
  methods: {

    //银行
    getBanklb() {
      getBank().then(res => {
        res.retData.forEach((val) => {
          this.bankVal.push({value: val.descrshort, key: val.bankCd})
        });
      })
    },


    save() {
      console.log(this.bank)
      savePbnk(json2Form(this.bank)).then(res => {
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          this.$vux.alert.show({
            title: '奥克斯',
            content: '保存成功',
            onHide () {
              that.$router.push({
                name: 'userBase',
                params:{
                  cnta: that.bank.cTransactionNbr
                }
              });
            }
          })
      }

        }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    getBanks() {
      if(this.$route.params.banklt){
        this.bank.bankCd = this.$route.params.banklt.bankCd
        this.bank.rsBranchNm = this.$route.params.banklt.rsBranchNm
        this.bank.accountEcId = this.$route.params.banklt.accountEcId
        this.bank.accountName = this.$route.params.banklt.accountName
        this.bank.cTransactionNbr = this.$route.params.ctn
        if(!this.$route.params.ctn){
          this.showOr = false
        }
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss" scoped>
@import "./personstyle";
</style>
